<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>非受控组件</title>
</head>

<body>
    <!--准备好一个容器-->
    <div id="test"></div>
    <!--引入核心库-->
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <!--引入react-dom支持react操纵dom-->
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <!--引入babel用于将jsx转为js-->
    <script src="../js/babel.min.js"></script>
    <!--引入prop-types,用于对标签属性进行限制-->
    <script src="../js/prop-types.js">//引入之后全局会产生一个PropType对象</script>

    <script type="text/babel">

        /*
        现用现取 需要用到ref
        */
        //创建组件
        class Login extends React.Component {
            handleSubmit = (event) => {
                event.preventDefault()//阻止表单提交
                const { username, password } = this//用解构赋值获取到属性key
                alert(`用户名为:${username.value},密码为:${password.value}`)
            }
            render() {
                return (
                    <form onSubmit={this.handleSubmit}>
                        用户名: <input ref={c => this.username = c} type="text" name="username" />
                        密码: <input ref={c => this.password = c} type="text" name="password" />
                        <button>登录</button>
                    </form>
                )
            }
        }
        //渲染组件
        ReactDOM.render(<Login />, document.getElementById('test'))
    </script>
</body>

</html>